 <#if authority.is(3,"3") >
<div id="usersmod" align="center">
<form name="usersmod_form" id="usersmod_form">
<input type="hidden" name="scid" value="user_4">
<input type="hidden" name="id" id="id" >
<table width="400px" height="100px">
	<tr>
		<td>用户名：</td>
		<td><input id="username" type="text" name="username" maxlength="20"  value="" /></td>
	</tr>
	<tr>
		<td>姓     名：</td>
		<td><input id="realname" type="text" name="realname"  value="" /></td>
	</tr>
	<tr>
		<td>邮     件：</td>
		<td><input id="email" type="text" name="email"  value="" /></td>
	</tr>
	<tr>
		<td>性     别：</td>
		<td><input id="gender" type="radio" name="gender"  value="0" >男
			<input id="gender" type="radio" name="gender" value="1" >女</td>
	</tr>
	<tr>
		<td>电     话：</td>
		<td><input id="phone" type="text" name="phone"  value="" /></td>
	</tr>
	<tr>
		<td>试用结束时间：</td>
		<td><input class="calendar input" id="endtime" name="endtime" type="text" /></td>
	</tr>
	<tr>
		<td>状     态：</td>
		<td>
			<select size="1" id="state" name="state">
		    <option value="0">正常</option>
		    <option value="1">删除</option>
		    <option value="2">隐藏</option>
			</select>
		</td>
	</tr>
	<tr collspan="2">
		<td width="78px" height="30px"><input name="bsubmit" id="bsubmit" type="button" value="提交" /><div id="submiting"></div></td>	
	</tr>
</table>
</form>
</div>

<div><table width="98%" border="0" cellpadding="0" cellspacing="1" >
   <tr>
       <td width="300" >当前所属角色</td>
	   <td width="100"><strong> 操作 </strong></td>
       <td width="300" >其他角色</td>
   </tr>
   <tr>
      <td width="300" valign="top">
          <div id="div_users_role"></div>
      </td>
      <td width="100">
           <input id="addRole" type="button" value="<< 添加"  width="80"/>
           <input id="removeRole" type="button" value="删除 >>" width="80"/>
      </td>
      <td width="300" valign="top">
      <div id="div_all_role"></div>
      </td>
    </tr>
</table></div>

<script type="text/javascript">
var dataURL = '/data/sc.action';//取数据的url
var dataURLParams = {"scid":"user_2","id":item_value};//要传给dataURL的参数
var mainPanel = 'mainPanel';
var fillcontent = function(){
try {
	var request = new Request.JSON({
		url: dataURL,
		onComplete: function(json,text) {
			 if(null != json.recorders && json.recorders.length>0){
					$('username').set('value',json.recorders[0].username);
					$('realname').set('value',json.recorders[0].realname);
					//$('password').set('value',json.recorders[0].password);
					$('email').set('value',json.recorders[0].email);
					$('phone').set('value',json.recorders[0].phone);
					
					var m = document.getElementsByName('gender'); 
		    	    var l = m.length;
		            for ( var i=0; i< l; i++)
		            {
						if(m[i].value==json.recorders[0].gender) 
							$(m[i]).set('checked',true); 
					}		
					$('state').set('value',json.recorders[0].state);
					// alert(json.recorders[0].endtime);
					$('endtime').set('value',json.recorders[0].endtime);
				}else{
					MUI.notification('<font color=red>错误：</font>未取到角色信息, id = '+item_value);
				}
		}
	}).get(dataURLParams);
	} catch (ex) {
		MUI.notification('<font color=red>错误：</font>访问失败('+ex.message+')');
	}
}

var userRoles;
var userRoles_pageno = 1;
if (userRoles) { userRoles_pageno = userRoles.findCurrentPage(); }

var allroles=null;
var allroles_pageno = 1;
if (allroles) { allroles_pageno = allroles.findCurrentPage(); }

var loadUserRolesList = function(){
	var dataURL =  '/data/sc.action';//取数据的url
	dataURLParams = {"scid":"user_7","userRoles_pageno":1,"userid": item_value };//要传给dataURL的参数
	var instanceName = 'userRoles';//MUI.List实例名称
	var divId = "userRoles_list";
	var columns = [{text:'序号',name:'id'},{text:'角色名',name:'rolename'},{text:'说明',name:'note'}];//要显示的字段
	if (!userRoles){
		userRoles = new MUI.List({
			instanceName:instanceName,
	       	container:'div_users_role',
	       	showCheckBox:true,
			showCommand:false,
	       	id:divId,
	       	columns:columns,
	       	dataURL:dataURL,
	       	dataURLParams:dataURLParams,
	       	cbName: 'ids0',
	       	saveCheck:true,
	       	commands:[],
	       	onItemCommand: function(item,self,cmd,img) {},
	       	onItemChecked: function(item,self,cmd,img) {},
	       	onItemSelected: function(item,self,cmd,img) {},
	       	onItemColumnBound: function(item,self,col,td) {}
	   	});//MUI.List
   	}
   	userRoles.setDataURLParams(dataURLParams);
   	userRoles_pageno = 1;
   	userRoles.findList(userRoles_pageno);
}

var loadAllRolesList = function(){
	var dataURL =  '/data/sc.action';//取数据的url
	dataURLParams = {"scid":"auth_6","allroles_pageno":1, "userid": item_value };//要传给dataURL的参数
	var instanceName = 'allroles';//MUI.List实例名称
	var divId = "allRole_list";//要填充的div编号
	var columns = [{text:'序号',name:'id'},{text:'角色名',name:'name'},{text:'说明',name:'note'}];//要显示的字段
	if (!allroles){
		allroles = new MUI.List({
			instanceName:instanceName,
	       	container:'div_all_role',
	       	showCheckBox:true,
			showCommand:false,
	       	id:divId,
	       	columns:columns,
	       	dataURL:dataURL,
	       	dataURLParams:dataURLParams,
	       	cbName: 'ids1',
	       	saveCheck:true,
	       	commands:[],
	       	onItemCommand: function(item,self,cmd,img) {},
	       	onItemChecked: function(item,self,cmd,img) {},
	       	onItemSelected: function(item,self,cmd,img) {},
	       	onItemColumnBound: function(item,self,col,td) {}
	   	});//MUI.List
   	}
   	allroles.setDataURLParams(dataURLParams);
   	allroles_pageno = 1;
   	allroles.findList(allroles_pageno);
}

new MUI.Require({
  js: [MUI.path.plugins + 'mochaList/List.js'],
  onload: function(){
	loadUserRolesList();
   	loadAllRolesList();
  } 
}); 

 window.addEvent('domready', function() {
 	fillcontent();
	$('bsubmit').addEvent('click', function(e){
		$('usersmod_form').set('send', {
    		url: dataURL, 
    		onSuccess:function(responseText, responseXML){
    			//alert(responseText);
    			$('bsubmit').set('disabled', false);
    			$('submiting').innerHTML = '';
    			var myjson = JSON.decode(responseText);
    			if (myjson.error.errorcode==0){
    				MUI.notification('修改成功！');
    				MUI.updateContent({
						'element':  $(mainPanel),
						'url':      '/auth/users.action'
					});
    			}else{
    				MUI.notification('<font color=red>错误：</font>('+myjson.error.retstring+')');
    			}
    		},
    		onFailure:function(instance){
    			MUI.notification('<font color=red>错误：</font>访问失败('+instance+')');
    			$('bsubmit').set('disabled', false);
    			$('submiting').innerHTML = '';
    		}
		});
		$('bsubmit').set('disabled', true);
		$('id').set('value',item_value);
		$('submiting').innerHTML = '<img src="images/spinner.gif" width="16px" height="16px">';
		$('usersmod_form').send();
	});
	
	$('addRole').addEvent('click', function(e){
		var checkids =  allroles.getcurCheckIds();
		if(null==checkids || ""==checkids) { alert('必须选择一项要添加的角色'); return; }
		checkids = checkids + "";
		allroles.clearCheckIds();
		var dataURL = '/data/sc.action'; 
		var dataURLParams = {"scid":"user_6", "id":item_value, "roleid":checkids};
		try {
			var request = new Request.JSON({
			url: dataURL,
			onComplete: function(json,text) {
				if (json.error.errorcode==0){
    				MUI.notification('添加成功！');
    				userRoles_pageno = 1;
    				allroles_pageno = 1;
    				loadUserRolesList(); 
    				loadAllRolesList();
    			}else{
    				MUI.notification('<font color=red>错误：</font>('+myjson.error.retstring+')');
    			}
			}
		}).get(dataURLParams);
		} catch (ex) {
			MUI.notification('<font color=red>错误：</font>('+json.error.retstring+')');
		}
	});
	
	$('removeRole').addEvent('click', function(e){
		var checkids =  userRoles.getcurCheckIds();
		if(null==checkids || ""==checkids) { alert('必须选择一项要移除的角色'); return; }
		checkids = checkids + "";
		// alert(checkids);
		userRoles.clearCheckIds();
		var dataURL = '/data/sc.action'; 
		var dataURLParams = {"scid":"user_8", "userid":item_value, "checkids":checkids};
		try {
			var request = new Request.JSON({
			url: dataURL,
			onComplete: function(json,text) {
				if (json.error.errorcode==0){
    				MUI.notification('移出成功！');
    				userRoles_pageno = 1;
    				allroles_pageno = 1;
    				loadUserRolesList(); 
    				loadAllRolesList();
    			}else{
    				MUI.notification('<font color=red>错误：</font>('+myjson.error.retstring+')');
    			}
			}
		}).get(dataURLParams);
		} catch (ex) {
			MUI.notification('<font color=red>错误：</font>('+json.error.retstring+')');
		}
	});
 });
</script>
<#else>
您无权访问该页面！
</#if>